package com.smarthome.web.property.controller.statisticsquery;

import java.text.ParseException;
import java.text.SimpleDateFormat;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

import javax.annotation.Resource;
import javax.servlet.http.HttpServletRequest;

import org.apache.commons.lang.StringUtils;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

import com.smarthome.core.statisticsquery.VillageStatisticsService;
import com.smarthome.domain.bean.ShResidence;
import com.smarthome.domain.vo.boss.Combobox;
import com.smarthome.domain.vo.boss.DataGrid;
import com.smarthome.domain.vo.boss.PageHelper;

/**
 * 小区查询控制类
 * @author cyj
 *
 */
@Controller
@RequestMapping("/villageStatisticsController")
public class VillageStatisticsController {

    @Resource
    private VillageStatisticsService villageStatisticsService;
    

    /**
     * 
    * @Title: dataGrid 
    * @Description: TODO(获得小区数据表格) 
    * @param residence
    * @param page
    * @param request
    * @return
    * DataGrid
    * @throws 
    * @author cyj
     */
    @RequestMapping("/dataGrid")
    @ResponseBody
    public DataGrid dataGrid(ShResidence residence, PageHelper page,HttpServletRequest request) {
    	String startCreate = request.getParameter("startCreate");
    	String endCreate = request.getParameter("endCreate");
    	String startModify = request.getParameter("startModify");
    	String endModify = request.getParameter("endModify");
    	SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd hh:mm:ss");
    	if(StringUtils.isNotBlank(startCreate)) {
    		try {
    			residence.setStartGmtCreate(sdf.parse(startCreate));
			} catch (ParseException e) {
				e.printStackTrace();
			}
    	}
    	if(StringUtils.isNotBlank(endCreate)) {
    		try {
    			residence.setEndGmtCreate(sdf.parse(endCreate));
			} catch (ParseException e) {
				e.printStackTrace();
			}
    	}
    	if(StringUtils.isNotBlank(startModify)) {
    		try {
    			residence.setStartGmtModify(sdf.parse(startModify));
			} catch (ParseException e) {
				e.printStackTrace();
			}
    	}
    	if(StringUtils.isNotBlank(endModify)) {
    		try {
    			residence.setEndGmtModify(sdf.parse(endModify));
			} catch (ParseException e) {
				e.printStackTrace();
			}
    	}
        return villageStatisticsService.dataGrid(residence, page);
    }

    /**
     * 
    * @Title: getComboData 
    * @Description: TODO(获取小区查询需要的combo数据) 
    * @return
    * Map<String,Object>
    * @throws 
    * @author cyj
     */
    @RequestMapping("/getComboData")
    @ResponseBody
    public Map<String,Object> getComboData() {
    	Map<String,Object> result = new HashMap<>();
    	List<Combobox> property = villageStatisticsService.property(false);
    	result.put("property", property);
    	return result;
    }
}
